package net.zjitc;



import javax.mail.*;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import java.util.Properties;

/**
 * @author 赵晶晶
 * @date 2018/11/14 12:55
 * @Vsersion .0
 */
public class Demo {
    public static void main(String[] args) throws Exception {
        Properties properties = new Properties();
        //设置邮箱服务器
        properties.setProperty("mail.host","smtp.qq.com");
        properties.setProperty("mail.smtp.auth","true");
        properties.setProperty("mail.smtp.port","587");

        Authenticator authenticator = new Authenticator() {
            @Override
            protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication("370268540@qq.com","yabkkclbhjvxbhde"); //授权码
            }
        };

        Session session = Session.getInstance(properties,authenticator);


        //创建一个代表邮件对象的Message
        Message message = new MimeMessage(session);
        //设置内容
        //发送给谁（谁发，发谁）
        message.setFrom(new InternetAddress("370268540@qq.com"));

        message.addRecipient(Message.RecipientType.TO,new InternetAddress());

        //设置标题
        message.setSubject("");
        message.setContent("","text/html;charset=utf-8");

        Transport.send(message);

    }
}
